package cn.smart99.homepage.ui.view;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;

import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import cn.smart99.homepage.R;

//import cn.smart99.homepage.R;

/*******************
 created by yang

 2016年1月26日

 *******************/

public class HomeItemView extends LinearLayout {

    private View        mView;
    private ImageView   mImageView;
    private TextView    mTextView;

    public HomeItemView(Context context) {
        this(context, null, 0);

    }

    public HomeItemView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public HomeItemView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        if(!isInEditMode()){
            mView = LayoutInflater.from(context).inflate(R.layout.homeitem_view,this);
            mImageView = (ImageView) mView.findViewById(R.id.homeitem_image);
            mTextView = (TextView) mView.findViewById(R.id.homeitem_text);
            this.setFocusable(true);

            TypedArray a = context.obtainStyledAttributes(attrs,R.styleable.HomeItemView);
            String str = a.getString(R.styleable.HomeItemView_text);
            if(str != null)  mTextView.setText(str);
            Log.d("tag","str=" + str);
            int resId = a.getResourceId(R.styleable.HomeItemView_src, -1);
            if(resId != -1) mImageView.setImageResource(resId);
            a.recycle();
        }

    }

    private void init(Context context) {

    }

    public void setText(String text){
        mTextView.setText(text);
    }

    public void setText(int id){
        mTextView.setText(id);
    }

    public void setImage(Drawable drawable){
        mImageView.setImageDrawable(drawable);
    }

    public void setImage(int id){
        mImageView.setImageResource(id);
    }
}

